package com.adjy.pathbuilders.physics;

import org.jbox2d.callbacks.ContactImpulse;
import org.jbox2d.callbacks.ContactListener;
import org.jbox2d.collision.Manifold;
import org.jbox2d.collision.WorldManifold;
import org.jbox2d.dynamics.contacts.Contact;

import com.adjy.pathbuilders.objects.GameEntityType;
import com.adjy.pathbuilders.world.GameEntity;

public class EntityContactListener implements ContactListener {
	
	@Override
	public void preSolve(Contact contact, Manifold manifold) {
	}
	
	@Override
	public void postSolve(Contact contact, ContactImpulse contactImpulse) {
	}
	
	@Override
	public void endContact(Contact contact) {
		GameEntity e1 = (GameEntity) contact.m_fixtureA.m_body.m_userData;
		GameEntity e2 = (GameEntity) contact.m_fixtureB.m_body.m_userData;
		
		if (e1 != null)
			e1.hasStoppedCollidingWith(e2, contact);
		if (e2 != null)
			e2.hasStoppedCollidingWith(e1, contact);
		
	}
	
	@Override
	public void beginContact(Contact contact) {
		GameEntity e1 = (GameEntity) contact.m_fixtureA.m_body.m_userData;
		GameEntity e2 = (GameEntity) contact.m_fixtureB.m_body.m_userData;
		
		if (e1 != null)
			e1.hasStartedCollidingWith(e2, contact);
		if (e2 != null)
			e2.hasStartedCollidingWith(e1, contact);
	}
}
